/**
 * 
 */
package com.clh.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.clh.dao.AdminDao;
import com.clh.entity.Admin;
import com.clh.util.DBUtil;

/**
 * @Description: 管理员Dao实现类
 * @author 邱凯臻
 * @date 2022年5月25日 下午3:16:08
 * @version v1.0
 */
public class AdminDaoImpl implements AdminDao {

	/**
	 * 查询所有管理员列表
	 * 
	 * @return
	 */
	@Override
	public List<Admin> find() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Admin findByCondition(Admin admin) {
		Admin admin_temp = null;
		StringBuilder sql = new StringBuilder();
		sql.append("select").append(" *").append(" from admin");

		if (true) {
			sql.append(" where 1 = 1");
		}

		if (admin.getAdminName() != null && !"".equals(admin.getAdminName()) && admin.getAdminPassword() != null
				&& !"".equals(admin.getAdminPassword())) {
			sql.append(" and admin_name = '" + admin.getAdminName() + "'"+" and admin_password = '" + admin.getAdminPassword() + "'");
		}

		// System.out.println(sql);
		ResultSet rs = DBUtil.query(sql.toString());
		try {
			while (rs.next()) {
				admin_temp = new Admin();
				admin_temp.setAdminId(rs.getInt("admin_id"));
				admin_temp.setAdminName(rs.getString("admin_name"));
				admin_temp.setAdminPassword(rs.getString("admin_password"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return admin_temp;
	}

}
